package cn.xi.service.checkItem;

import cn.xi.checkItem.CheckItemService;
import cn.xi.dao.CheckItemDao;
import cn.xi.entity.PageResult;
import cn.xi.entity.QueryPageBean;
import cn.xi.entity.Result;
import cn.xi.pojo.CheckItem;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;

    @Override
    public void save(CheckItem checkItem) {
        checkItemDao.save(checkItem);
    }

    @Override
    public void update(CheckItem checkItem) {
        System.out.println(checkItem);
        checkItemDao.update(checkItem);
    }

    @Override
    public void delete(Integer id) {
        checkItemDao.delete(id);
    }

    @Override
    public PageResult findpage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        PageHelper.startPage(currentPage, pageSize);
        Page<CheckItem> page =null;
        if (queryString != null && queryString.length() > 0) {
           page= checkItemDao.findPagewhere(queryString);
        }else {
            page= checkItemDao.findPage();
        }
        long total = page.getTotal();
        List<CheckItem> result = page.getResult();

        return new PageResult(total, result);
    }

    @Override
    public CheckItem findById(Integer id) {
        System.out.println(id);
        CheckItem r = checkItemDao.findById(id);
        return r;
    }
}
